package com.qdhh.enrollment.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qdhh.enrollment.common.Result;
import com.qdhh.enrollment.dto.QuizSubmissionQueryDTO;
import com.qdhh.enrollment.service.QuizSubmissionService;
import com.qdhh.enrollment.vo.QuizSubmissionVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 管理员考试记录控制器
 */
@Tag(name = "管理员考试记录管理", description = "考试记录的查询、统计接口")
@RestController
@RequestMapping("/api/admin/records")
public class AdminRecordController {

    private final QuizSubmissionService quizSubmissionService;

    public AdminRecordController(QuizSubmissionService quizSubmissionService) {
        this.quizSubmissionService = quizSubmissionService;
    }

    @Operation(summary = "分页查询考试记录")
    @GetMapping
    public Result<IPage<QuizSubmissionVO>> listRecords(
            @Parameter(description = "页码") @RequestParam(defaultValue = "1") int page,
            @Parameter(description = "每页数量") @RequestParam(defaultValue = "10") int size,
            @Parameter(description = "学生ID") @RequestParam(required = false) String studentId,
            @Parameter(description = "是否通过") @RequestParam(required = false) Integer passed) {
        QuizSubmissionQueryDTO queryDTO = new QuizSubmissionQueryDTO();
        queryDTO.setPage(page);
        queryDTO.setSize(size);
        queryDTO.setStudentId(studentId);
        queryDTO.setPassed(passed);
        
        IPage<QuizSubmissionVO> result = quizSubmissionService.querySubmissions(queryDTO);
        return Result.success(result);
    }

    @Operation(summary = "获取考试统计信息")
    @GetMapping("/statistics")
    public Result<Map<String, Object>> getStatistics() {
        Map<String, Object> statistics = quizSubmissionService.getStatistics();
        return Result.success(statistics);
    }
}

